﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WordDowngrade
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void setDialog(OpenFileDialog dialog)
        {
            dialog.Multiselect = true;
            dialog.Title = "Please Choose Files";
            dialog.Filter = "Office 2007 Files (*.docx;*.xslx)|*.docx";
        }
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            FolderBrowserDialog destDialog = new FolderBrowserDialog();
            destDialog.Description = "Please Select The Destination Folder";
            setDialog(dialog);
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                if (destDialog.ShowDialog() == DialogResult.OK)
                {

                    String destFolder = destDialog.SelectedPath;
                    String[] newFilesNames = new String[dialog.FileNames.Length];
                    for (int i = 0; i < newFilesNames.Length; i++)
                    {
                        newFilesNames[i] =destFolder+"\\"+ Path.GetFileNameWithoutExtension(dialog.FileNames[i]);
                    }
                    Form2 f = new Form2(newFilesNames.Length);
                    f.Show();
                    for (int i = 0; i < dialog.FileNames.Length; i++)
                    {
                        f.workingOn(Path.GetFileNameWithoutExtension(dialog.FileNames[i]));
                        Downgrader.Downgrade(dialog.FileNames[i],newFilesNames[i]);
                        f.increaseProgress();
                    }
                    f.Close();
                }
            }
        }
    }
}
